package com.at.abc.r419_e;

import java.io.*;
import java.util.PriorityQueue;

public class b {

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StreamTokenizer in = new StreamTokenizer(br);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        solve();
        out.flush();
        out.close();
        br.close();
    }

    static void solve() throws IOException {
        in.nextToken(); int q = (int) in.nval;
        PriorityQueue<Integer> pq = new PriorityQueue<>();
        while (q-- > 0) {
            in.nextToken(); int a = (int) in.nval;
            if (a == 1) {
                in.nextToken(); int b = (int) in.nval;
                pq.add(b);
            } else if (a == 2) {
                out.println(pq.poll());
            }
        }
    }
}
